package day240802;
/*
 启动新路径
 方法一：extends Thread&& Override run() && start()
 方法二: implements Runnable && implement run() && new Thread(...).start()
 方法其他：后续补充
 */
public class ThreadNewPath {
    public static void main(String[] args) {
        MyThread1 myThread1 = new MyThread1("Thread-path1");
        //myThread1.start();//开辟新线程, 两线程：main和新线程，在新线程运行
        //直接调用run方法,相当普通方法调用，没有启用新执行路径
        //myThread1.run();
        //调用start方法，启动新执行路径
        myThread1.start();


        Thread myThread2 = new Thread(new MyThread2(),"Thread-path2");
        myThread2.start();
        Thread myThread3= new Thread(() -> {
                for (int i = 0; i < 100; i++) {
                    System.out.println(Thread.currentThread().getName()+"---"+i);
            }
        });
        myThread3.start();
    }
}
class MyThread1 extends Thread {
    public MyThread1(){
    }
    public MyThread1(String name){
        super(name);
    }
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println(this.getName() + "---" + i);

        }
    }
}
class MyThread2  implements Runnable{
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println(Thread.currentThread().getName() + "---" + i);
        }
    }
}